<?php
// $regex_valid_variable_name = "'^[A-Za-z_][A-Za-z0-9_]*$";

// ^ in this context means that the regex is anchored
// to the beginning of the string.
//
// A single [xxx] means that a single letter must mach
// the criteria within
//
// The [xxx]* means that [xxx] can mach from zero to
// unlimited times.
//
// The $ is another anchor, except it is for the end of 
// the sting.

// Valid names: "_", "hello1", "a_variable"
// Invalid names: "4number", "five-to", "one two", " space "

//Test it out:
$valid = array ( '_', 'hello1', 'a_variable' );
$invalid = array ( '4number', 'five-to', 'one two', ' space ');
foreach($valid as $v)
    echo 'Valid '.
(ereg('^[A-Za-z_][A-Za-z0-9_]*$', $v) ? 'yes' : '<b>no</b>') . ": $v<br />\n";

foreach($invalid as $v)
    echo 'Invalid '.(!ereg('^[A-Za-z_][A-Za-z0-9_]*$', $v) ? 'yes' : '<b>no</b>') . ": $v<br />\n";
?> 


